﻿using DFGK_WMS.IRepository;
using DFGK_WMS.Model.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DFGK_WMS.Repository
{
    public class AGVRepository : IAGVRepository
    {
        /// <summary>
        /// 出入库任务
        /// </summary>
        /// <param name="sendTaskDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<string> SendTask(SendTaskDto sendTaskDto)
        {
            // 第三方接口的URL和参数
            string apiUrl = "https://api.third-party.com";
            string apiKey = "your-api-key";
            string requestData = $"{{ \"startPoint\": \"{sendTaskDto.StartPoint}\", \"taskType\": \"{sendTaskDto.TaskType}\", \"endPoint\": \"{sendTaskDto.EndPoint}\" , \"taskCode\": \"{sendTaskDto.TaskCode}\"}}";
            string responseBody = "";

            try
            {
                // 创建HTTP客户端
                using (HttpClient client = new HttpClient())
                {
                    // 添加请求头信息
                    client.DefaultRequestHeaders.Add("API-Key", apiKey);
                    // 发送POST请求，传递JSON数据
                    HttpResponseMessage response = await client.PostAsync(apiUrl, new StringContent(requestData, System.Text.Encoding.UTF8, "application/json"));

                    // 检查响应状态码
                    response.EnsureSuccessStatusCode();

                    // 解析响应数据
                    responseBody = await response.Content.ReadAsStringAsync();

                    return responseBody;

                    // 处理响应数据
                    //Console.WriteLine("Response: " + responseBody);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
